<#assign pageName="审批分组管理">
<#function getDepName depid>
    <#if depList?has_content>
        <#list depList as dep>
            <#if depid!=""&dep.depId?string==depid?string>
                <#return dep.depName>
            </#if>
        </#list>
    </#if>
    <#return "">
</#function>
 <#function getUpperId depid>
    <#if depList?has_content>
        <#list depList as dep>
            <#if depid!=""&dep.depId?string==depid?string>
                <#return dep.upperId>
            </#if>
        </#list>
    </#if>
    <#return "">
</#function>
<@override name="head-styles">
    <link rel="stylesheet" href="${contextPath}/assets/plugins/ztree/css/bootstrapStyle/bootstrapStyle.css" type="text/css">
    <link rel="stylesheet" href="${contextPath}/assets/css/bootstrap.min.css">
</@override>
<@override name="page-content">
<form class="layui-form form-horizontal" role="form" method="post">
    <div class="layui-form-search panel">
        <input type="text" hidden="hidden" name="_STATE"/>
        <input type="text" hidden="hidden" name="groupCode" id="groupCode"/>
        <@ctrl.TextboxQuery path="wfGroup.Name" labelText="分组名称"/>
        <@ctrl.TextboxQuery path="wfGroup.Code" labelText="分组编号"/>
        <div class="margin-5">
           <a href="javascript:"  onclick="$('#pageNo').val(1);$('form:first').submit();" class="layui-btn layui-btn-sm">
               <i class="layui-icon layui-icon-search"></i>查询
           </a>
           <a href="javascript:" class="layui-btn layui-btn-warm layui-btn-sm js-reset">
                <i class="layui-icon layui-icon-refresh-1"></i>重置
            </a>
           <a href="add" class="layui-btn layui-btn-normal layui-btn-sm">
               <i class="layui-icon layui-icon-addition"></i>新增
           </a>
        </div>
    </div>
    <table class="layui-table">
        <thead>
            <tr>
                <th class="align-center" width="5%" nowrap="nowrap">序号</th>
                <th class="align-center">分组名称</th>
                <th class="align-center" width="8%">分组编号</th>
                <th class="align-center" width="15%">分组描述</th>
                <th class="align-center" width="10%">创建时间</th>
                <th class="align-center" width="10%">启用状态</th>
                <th class="align-center" width="20%">操作</th>
            </tr>
        </thead>
        <tbody>
        <#if queryResult.rows?has_content>  
            <#list queryResult.rows as dataItem>  
            <tr>
                <td class="align-center" width="50px" nowrap="nowrap">
                    ${(pageNo-1)*pageSize+dataItem_index+1} 
                </td>
                <td class="align-center">${dataItem.name}</td>  
                <td class="align-center">${dataItem.code}</td>
                <td class="align-center">${dataItem.content}</td>
                <td class="align-center">${dataItem.createTime?datetime}</td>
                <td class="align-center">${dataItem.status}</td>
                <td class="align-center">
                    <div class="btn-group">
                    	<a href="javascript:" onclick="addUser(${dataItem.code});" class="layui-btn layui-btn-normal layui-btn-xs">
                            <i class="layui-icon layui-icon-addition"></i>用户
                         </a>
                        <a href="edit/${dataItem.id}" class="layui-btn layui-btn-xs layui-btn-warm">
                            <i class="layui-icon layui-icon-edit"></i>修改
                         </a>
                        <button type="button" class="layui-btn layui-btn-xs layui-btn-danger" 
                            onclick="confirmSubmit('确认删除‘${dataItem.name}’分组吗？',{groupId: '${dataItem.id}'},'del')">
                            <i class="layui-icon layui-icon-delete"></i>删除
                        </button>
                        <a href="detail/${dataItem.id}" class="layui-btn layui-btn-normal layui-btn-xs">
                            <i class="layui-icon layui-icon-about"></i>详情
                        </a>
                    </div>
                </td>
            </tr>
            </#list>
        <#else>
            <tr class="align-center">
                <td style="color:red;font-weight:bold;" colspan="8">暂无符合条件的数据！</td>
            </tr>
        </#if>
        </tbody>
    </table>
    <@ctrl.pageShow (queryResult.total)!0, (queryResult.pageIndex)!0 />
      <!--模态框-->
   <div id="modal_box" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="gridSystemModalLabel">
       <div class="modal-dialog" role="document">
          <div class="modal-content">
              <div class="modal-header">
                 <h4 class="blue" id="modalTitle"></h4>
              </div>
              <div class="modal-body">
     				<ul id="selectBox" class="ztree"></ul>
              </div>
              <div class="modal-footer">
                 <input type="hidden" id="type" name="type" />
                 <button type="button" onclick="modalConfirm()" class="btn btn-success">确认</button>
                 <button type="button" onclick="modalCancel()" class="btn btn-default">取消</button>
              </div>
          </div><!-- /.modal-content -->
       </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
</form>
</@override>
<@override name="page-scripts">
<script>
    $(function(){
        layui.use(['form','layer','element', 'jquery'], function(){
            var form=layui.form;
            var layer=layui.layer;
            var element = layui.element;
            var $ = layui.jquery;
            $('.js-reset').on('click', function(){
                $('#pageNo').val(1);
                $('#Name').val("");
                $('#Code').val("");
                $('form:first').submit();
            });
        })
    })
</script>
<script type="text/javascript" src="${contextPath}/assets/plugins/ztree/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="${contextPath}/assets/plugins/ztree/js/jquery.ztree.excheck.js"></script>
<script type="text/javascript" src="${contextPath}/assets/plugins/ztree/js/jquery.ztree.exedit.js"></script>
<script src="${contextPath}/assets/js/bootstrap.min.js"></script>
<script>
	function addUser(groupCode){
		$('#groupCode').val(groupCode);
		var setting = {
				view: {
                    selectedMulti: false,
                },
                check: {
                    enable: true,
                    chkStyle: "checkbox",
                    chkboxType: { "Y": "", "N": "" }
                },
                data: {
                    simpleData: {
                        enable: true
                    }
                },
                edit: {
                    enable: false
                },
                view:{
                    selectedMulti: false
                },
                callback: {
                    onCheck: myDepandUserCheck
                }
		 };
		 var zNodes = [
		  <#if depList?has_content>
		      <#list depList as dataItem>
		          {id:"${dataItem['depId']}",pId:"${getUpperId(dataItem.depId)}",name:"${dataItem['depName']}",isParent:"true",nocheck:"true"},
		          <#list wfUserList as uItem>
			          <#if dataItem.depId==uItem.dep_id>
				          {id:"${uItem.id}",pId:"${uItem.dep_id}",name:"${uItem.user_name}"},
				       </#if>
			      </#list>
		      </#list>
		  </#if>
		  
		 ];
	    var gcode=$('#groupCode').val();
	    var checkedNodes = new Array();
	    <#if wfUserList?has_content>
		    <#list wfUserList as uItem>
		    	var groupCode='${uItem.group_code}';
		    	if(groupCode!=null&&groupCode!=""&&gcode==groupCode){
		    		checkedNodes.push({id:"${uItem.id}"});
		    	}
		     </#list>
		</#if>
		 //3.生成树形菜单
		$.fn.zTree.init($("#selectBox"),setting,zNodes);
		var treeObj = $.fn.zTree.getZTreeObj("selectBox");
		treeObj.expandAll(true);　
		for(var i = 0; i < checkedNodes.length; i++) {　
            // 回显选中的数据　　　
			 var node = treeObj.getNodeByParam("id", checkedNodes[i].id);//根据ID找到该节点
		     if(node != null){
		          treeObj.checkNode(node, true, false);//根据该节点选中
		     }
        }　
        $('#modalTitle').text("<用户>选择");
        $('#type').val("user");
        $('#modal_box').modal();
	}
	var ids;
	<!--模态框操作-->
    function myDepandUserCheck(event, treeId, treeNode){
    	ids = "";
        var treeObj = $.fn.zTree.getZTreeObj(treeId);
        var nodes = treeObj.getCheckedNodes(true);
        var Notnodes = treeObj.getCheckedNodes(false);
        for(var i=0;i<nodes.length;i++){
           ids=ids+","+nodes[i].id;
        }
    }
    
    <!--模态框确定-->
    function modalConfirm(){
        $('#selectBox').empty();
        jQuery.ajax({
            type     : 'POST',
            url      : '${contextPath}/workflow/group/userchoose',
            data    : {"ids":ids,"groupCode":$('#groupCode').val()},
            success  : function(data){
                if(data.msg==""){
                    $('#validate-box').modal("hide");
                    location.reload();
                }else{
                	location.reload();
                    alert(data.msg);
                }
            }
        });
        modalCancel();
    }
    <!--模态框取消-->
    function modalCancel(){
        $('#modal_box').modal('hide');
        $('#selectBox').empty();
        ids = "";
    }

</script>
</@override>
<@extends name="/layout/basepage.html"/> 
